<?php
  $pid = $_GET['pid'];
  $con = mysql_connect("mysql1.000webhost.com", "a7424976_info", "thebest5");
	$res = mysql_select_db("a7424976_info");
	
	$queryres = mysql_query("select * from inventory where state=$pid");
	
	echo "<HTML>
        <HEAD>
          <TITLE>&#51077;&#44256; &#47785;&#47197;</TITLE>
          <link rel='stylesheet' type='text/css' href='table.css'/>
        </HEAD>
          <BODY>
            <TABLE BORDER='0'>
            <thead>
        	    <tr>
        	       <th id='a1' scope='col'>&#54408;&#47785;</th>
        	       <th id='fn' scope='col'>&#45800;&#44032;(&#50896;)</th>
        ";
        
  if ($pid == 0){
    echo "<th id='fn' scope='col'>&#51077;&#44256; &#45216;&#51676;</th>
          </thead>";
  }
  else{
    echo "<th id='fn' scope='col'>&#52636;&#44256; &#45216;&#51676;</th>
          </thead>";
  }
        	  
  while($row = mysql_fetch_row($queryres)){
    echo "<tr>";
    for ($c=1; $c<=4; $c++){
      if ($c == 3) continue;
      echo "<th scope='row'>$row[$c]</th>";
    }
    echo "</tr>";
	}
	
	if ($pid == 0){
  	echo "<thead>
  	      <th colspan='3'>&#47932;&#54408; &#51077;&#44256; &#49688;</th>
  	    </thead>";
  }
  else{    
    echo "<thead>
  	      <th colspan='3'>&#47932;&#54408; &#52636;&#44256; &#49688;</th>
  	    </thead>";
  }
  
  
 	$q0 = mysql_query("select distinct name from inventory where state=$pid");
  while(($row = mysql_fetch_row($q0))){
    $q1 = mysql_query("select COUNT(*) from inventory where state=$pid and name='$row[0]'");
    $r1 = mysql_fetch_row($q1);
    
    echo "<tr><th scope='row'>$row[0]</th>
          <th scope='row' colspan='2'>$r1[0]</th></tr>";
  }
	mysql_close($con);
	echo "</TABLE>
  </BODY>
      </HTML>";

?>